/**
 * @file main.c
 * @brief 一般情况下不要修改此文件
 * @author He Shaohua (hsh15529870639@foxmail.com)
 * @date 2024-05-19
 * @version 1.0
 * @copyright Copyright (c) 2024, SNUT-Chaoyue Team
 * ****************************************************************************************************
 * @par Change Log:
 * <table>
 * <tr><th>Date         <th>Version       <th>Author      <th>Description
 * <tr><td>2024-05-19   <td> 1.0          <td>He Shaohua  <td>Creator
 *
 * </table>
 * ==================================----How to use this driver----=====================================
 * [..]
 * @note
 *   -# 系统默认使用FreeRTOS，如果不使用将预编译宏 USE_CORE_FREERTOS 删除 \n
 *
 * @warning
 *   -#
 *
 * *****************************************************************************************************
 * @attention
 *
 * This document is required and please understand any bugs that may occur in the document.
 * If you want to modify this file, after the code update is completed, update the version number in time,
 * indicate the update date, and fill in the changes
 * Make sure that the submitted code does not have many bugs.
 *
 * All rights reserved.
 * *****************************************************************************************************
 */
/* Includes Header -----------------------------------------------------------*/
#include "main.h"
/* Includes Header -----------------------------------------------------------*/
#include "App.h"
#include "drv_timer.h"
/* Private Task handle -----------------------------------------------------*/
static TaskHandle_t defaultTaskHandle = NULL;
/* Private Kernel object handle ---------------------------------------------*/
/* Private global variables -------------------------------------------------*/
/* Private function prototypes ----------------------------------------------*/
extern void xPortSysTickHandler(void);
void StartDefaultTask(void *argument);
/* Private functions --------------------------------------------------------*/
/**
 * @brief  Function implementing the defaultTask thread.
 * @param  argument: Not used
 * @retval None
 */
void StartDefaultTask(void *argument)
{
  /* Infinite loop */
  Robot_Run_once();
  for (;;)
  {
    Robot_Run();
    vTaskDelete(NULL);
  }
}

/**
 * @brief  The application entry point.
 * @retval int
 */
int main(void)
{
  BaseType_t xReturn = pdPASS;
  SYSCFG_DL_init();
  MY_TIMER_Init();
  Robot_Init();
  xReturn = xTaskCreate((TaskFunction_t)StartDefaultTask,
                        (const char *)"defaultTask",
                        (uint16_t)128,
                        (void *)NULL,
                        (UBaseType_t)1,
                        (TaskHandle_t *)&defaultTaskHandle);

  if (pdPASS == xReturn)
    vTaskStartScheduler();
  else
    while (1)
      ; // 进入这里说明FreeRTOS启动失败
  while (1)
  {
  }
}

/**
 * @brief 滴答定时器设置为1ms
 *
 */
void SysTick_Handler(void)
{
  if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
  {
    xPortSysTickHandler();
    MY_TIMER_Update();
  }
}